package com.hsxazj.springkafka.controller;

import com.alibaba.fastjson.JSONObject;
import jakarta.annotation.Resource;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

@RestController
@CrossOrigin(originPatterns = "*")
public class kafkaProducer {

    @Resource
    private KafkaTemplate<String, Object> kafkaTemplate;


    @GetMapping("/kafka/normal/{message}")
    public void sendNormalMessage(@PathVariable("message") String message) {
        Map<String, Object> map = new HashMap<>();
        map.put("msg", "success");
        map.put("data", "xxxxxxxx");
        map.put("code", 200);
        String jsonValue = JSONObject.toJSON(map).toString();
        kafkaTemplate.send("sb_topic", jsonValue);
    }

}
